package com.ruoyi.inspection.domain.receiveVo;

import cn.hutool.core.lang.UUID;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.constant.GlobalConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.inspection.constant.InspectionConstant;
import com.ruoyi.system.domain.LightningWarn;
import com.ruoyi.system.entity.LightningData;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * 上报雷电预警数据
 */
@Data
public class ReceiveThunderWarning implements Serializable {
    // 唯一编码，36 位uuid，必填
    private String crashNumber;
    // 设备编码 企业编码加三位流水号
    private String equipCode;
    // 预警等级 1:黄色预警 2:橙色预警 3:红色预警
    private String warningLevel;
    // 两位行政区划编码
    private String areaCode;
    /**
     * 预警开始时间
     */
    private String beginTime;
    /**
     * 预警结束时间
     */
    private String endTime;




    public static ReceiveThunderWarning lightningDataToReceiveThunderWarning(LightningWarn lightningWarn) {
        ReceiveThunderWarning receiveThunderWarning = new ReceiveThunderWarning();
//        receiveThunderWarning.setCrashNumber(enId(lightningWarn.getId() + lightningWarn.getStartTime()) + "-001");
        receiveThunderWarning.setCrashNumber(UUID.randomUUID().toString());
        receiveThunderWarning.setEquipCode(GlobalConstants.COMPANY_CODE + "100");
        receiveThunderWarning.setWarningLevel(lightningWarn.getAlarmLevel());
        receiveThunderWarning.setBeginTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date(Long.parseLong(lightningWarn.getStartTime()))));
        receiveThunderWarning.setEndTime(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", new Date(Long.parseLong(lightningWarn.getEndTime()))));

        return receiveThunderWarning;
    }

    public static String enId(String id) {
        String a = "ldyjxxsbqtxw-" + id + "-";
        String a1 = StrUtil.fillAfter(a, 'g', 32);
        return a1;
    }

}
